﻿// JScript File
function HighlightMenuItem(subItemID) {

    var nav = document.getElementById('ctl00_tdname');
    var nsItem = document.getElementById('ctl00_' + subItemID);


    if (nav != null && nsItem != null) {

        nav.value = nsItem;
        //alert(nav.value);

    }

}

function CheckBoxSelect() {



    var frm = document.forms[0];

    for (i = 0; i < frm.length; i++) {
        if (frm.elements[i].id.indexOf("chkSelect") != -1)  //check box
        {
            if (frm.elements[i].checked == true)   //checked
            {
                return true;
            }
        }
    }
    alert("请先选择要操作的记录！");
    return false;
}


function CheckBlank(id, message) {
    var obj = document.getElementById(id);
    if (obj != null && obj.value == '') {
        alert(message);
        return false;
    }
    return true;
}



function CheckAll_Old(chkVal, idVal) {
    alert(chkVal);
    var frm = document.forms[0];
    // Loop through all elements
    for (i = 0; i < frm.length; i++) {
        // Look for our Header Template's Checkbox
        if (idVal.indexOf('chkAll') != -1) {
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if (frm.elements[i].id.indexOf('chkSelect') != -1) {
                if (chkVal == true) {
                    frm.elements[i].checked = true;
                }
                else {
                    frm.elements[i].checked = false;
                }
            }
            // Work here with the Item Template's multiple checkboxes
        }
        else if (idVal.indexOf('chkSelect') != -1) {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if (frm.elements[i].checked == false) {
                document.getElementById('chkAll').checked = false; //Uncheck main select all checkbox

                break;

            }
        }
    }

}


function CheckAll(chkVal, idVal) {
    var chkList = document.documentElement.getElementsByTagName("INPUT");
    var chk;
    //var n=0;
    //var strid;
    //alert(idVal);
    if (chkVal == true && idVal.indexOf('chkAll') != -1) {

        for (var i = 0; i < chkList.length; i++) {
            chk = chkList[i];
            if (chk.type == "checkbox" && chk.id.indexOf("_chkSelect") > 0) {
                chk.checked = true;
            }
        }
    }

    else if (chkVal == false && idVal.indexOf('chkAll') != -1) {
        for (var i = 0; i < chkList.length; i++) {
            chk = chkList[i];
            if (chk.type == "checkbox" && chk.id.indexOf("_chkSelect") > 0) {
                chk.checked = false;
            }
        }
    }
    else if (idVal.indexOf('chkSelect') != -1) {
        if (!chkVal)
            document.getElementById('chkAll').checked = false;

    }

}

function CheckNewAll(chkVal, idVal) {
    var chkList = document.documentElement.getElementsByTagName("INPUT");
    var chk;
    //var n=0;
    //var strid;
    //alert(idVal);
    if (chkVal == true && idVal.indexOf('chkNewAll') != -1) {

        for (var i = 0; i < chkList.length; i++) {
            chk = chkList[i];
            if (chk.type == "checkbox" && chk.id.indexOf("_chkNewSelect") > 0) {
                chk.checked = true;
            }
        }
    }

    else if (chkVal == false && idVal.indexOf('chkNewAll') != -1) {
        for (var i = 0; i < chkList.length; i++) {
            chk = chkList[i];
            if (chk.type == "checkbox" && chk.id.indexOf("_chkNewSelect") > 0) {
                chk.checked = false;
            }
        }
    }
    else if (idVal.indexOf('chkNewSelect') != -1) {
        if (!chkVal)
            document.getElementById('chkNewAll').checked = false;

    }

}


function btnConfirm_OnClick(msg) {
    var post = confirm(msg);
    if (post)
        return true;
    else
        return false;
}

function btnSave_OnClick() {
    var post = confirm("您确认要保存当前的数据吗?");
    if (post)
        return true;
    else
        return false;
}

function btnDelete_OnClick() {
    var post = confirm("您确认要删除当前的数据吗?");
    if (post)
        return true;
    else
        return false;

}

//function ResizeDivForScroll(name)
//{
//    
//    var obj = document.getElementById(name);
//    
//    if(obj == null)
//        return;
//    if (obj.parentNode.clientWidth - obj.clientWidth > 5)
//    {
//        obj.style.width = obj.parentNode.clientWidth * 0.95;
//        
//    }
//}




function ResizeDivForScroll(name, obj) {
    var ofrm = window.parent.document.getElementById("main");
    if (ofrm != null) {
        //alert();
        var sHeight = ofrm.document.body.offsetHeight;
        var sWidth = ofrm.document.body.offsetWidth;


        var divReport = document.getElementById(name);
        if (divReport != null) {

            divReport.style.width = sWidth - 230;
            //alert(divReport.style.height);

            //                    if (divReport.style.height!="")
            //                    {
            if (obj != null)
                divReport.style.height = sHeight - 330;

            else
                divReport.style.height = sHeight - 290;
            //                    }

        }
    }
}

function resizeFuncAllPreContract() {
    var parentWin = window.parent;

    if (parentWin != null) {
        var ofrm = parentWin.document.getElementById("main");

        if (ofrm != null) {
            //alert("yes");
            var sHeight = ofrm.document.body.offsetHeight;
            var sWidth = ofrm.document.body.offsetWidth;

            var divReport = document.getElementById("ctl00_ContentPlaceHolder1_divReport");
            if (divReport != null) {
                divReport.style.width = sWidth - 260;
                divReport.style.height = sHeight - 280;
            }
        }
        else {
            //alert("no");
            var divReport = document.getElementById("ctl00_ContentPlaceHolder1_divReport");
            //alert(window.screen.availWidth);
            //alert(document.body.scrollHeight);
            //          alert(document.body.offsetHeight);
            //          alert(document.body.offsetWidth);
            //        alert(document.documentElement.clientHeight);          
            //          divReport.style.width = document.documentElement.clientWidth-50;
            //          divReport.style.height = document.documentElement.clientHeight-140;
            if (divReport != null) {
                divReport.style.width = document.body.offsetWidth - 50;
                divReport.style.height = document.body.offsetHeight - 170;
            }
        }
    }
}

function ConfirmSave(btnName) {
    if (confirm("您确定要保存吗？\nAre you sure to save?")) {
        var btn = document.getElementById("ctl00_ContentPlaceHolder1_" + btnName);
        if (btn != null)
            btn.removeAttribute("autopostback");
    }
    else
        event.returnValue = false;
}